package com.jt.demo1.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class TxAspect {

//    @AfterReturning(value = "pointCut()",returning = "result")
//    public void afterReturning(Object result){
//        System.out.println("方法的返回值："+result);
//    }
//    @AfterThrowing(value = "execution(* com.jt.demo1.service..*.*(..))",throwing ="exception")
//    public void afterThrowing(Exception exception){
//        System.out.println("异常信息："+exception.getMessage());
//    }

    @Around("bean(userServiceImpl)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long starTime = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间："+(endTime-starTime));

        Class targetClasss = joinPoint.getTarget().getClass();
        String targetName = joinPoint.getSignature().getDeclaringTypeName();
        String methodName = joinPoint.getSignature().getName();

        System.out.println("目标对象类型："+targetClasss);
        System.out.println("目标对象名称："+targetName);
        System.out.println("目标方法名称："+methodName);

        return result;


    }

    @AfterThrowing(value = "execution(* com.jt.demo1.service..*.*(..))",throwing ="exception")
    public void afterThrowing(Exception exception){
        System.out.println("异常信息："+exception.getMessage());
    }

}
